package com.lingxu.module.sjtjfx.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lingxu.module.collection.entity.ModelColumnInfo;
import com.lingxu.module.database.entity.TModel;
import com.lingxu.module.risk.entity.TModelRunRecord;
import com.lingxu.module.risk.mapper.TModelRunRecordMapper;
import com.lingxu.module.risk.service.RiskService;
import com.lingxu.module.sjtjfx.entity.FieldDTO;
import com.lingxu.module.sjtjfx.entity.StuationDTO;
import com.lingxu.module.sjtjfx.entity.WaringDataDTO;
import com.lingxu.module.sjtjfx.mapper.TjfxMapper;
import com.lingxu.module.sjtjfx.service.TjfxService;
import com.lingxu.module.sjtjfx.tool.TjfxTool;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.sql.ResultSetMetaData;
import java.util.*;
import java.util.stream.Collectors;

import static com.lingxu.module.risk.service.impl.RiskServiceImpl.getProjectNameKey;

@Service
public class TjfxServiceImpl implements TjfxService {

    @Resource
    private RiskService riskService;

    @Resource
    private TjfxMapper tjfxMapper;

    @Resource
    private TModelRunRecordMapper tModelRunRecordMapper;

    @Override
    public List<FieldDTO> queryFieldOverview() {

        List<FieldDTO> fieldDTOS = tjfxMapper.queryFieldOverview();
        for (FieldDTO fieldDTO : fieldDTOS) {
            if (fieldDTO.getYjNumber() == null) {
                fieldDTO.setYjNumber(0);
            }
        }
        return fieldDTOS;
    }

    @Override
    public Map<String, Object> queryWarningDataOverview() {
        HashMap<String, Object> map = new HashMap<>();

        Integer allWtNum = tjfxMapper.queryAllWtNum();
        map.put("totalNum", allWtNum);

        List<WaringDataDTO> waringDetails = tjfxMapper.queryWaringDetailsDTO();
        if (null != waringDetails) {
            for (WaringDataDTO waringDetail : waringDetails) {
                if (waringDetail.getWaringNum() == null || waringDetail.getWaringNum().trim().isEmpty()) {
                    waringDetail.setWaringNum("0");
                    waringDetail.setWaringProportion("0%");
                }
            }
        }
        map.put("waringDetails", waringDetails);
        return map;
    }

    @Override
    public Map<String, Object> queryExpectationBusinessProcessing() {
        List<StuationDTO> allModel = tjfxMapper.queryALLModelRunRecode();

        for (StuationDTO stuationDTO : allModel) {
            String table = stuationDTO.getResultTable();
            String resultColumns = stuationDTO.getResultColumns();
            List<ModelColumnInfo> modelColumnInfoList = JSON.parseArray(resultColumns, ModelColumnInfo.class);

        }
        return Collections.emptyMap();
    }
}
